<?php

/**
 * This is the model class for table "action_mail".
 *
 * The followings are the available columns in table 'action_mail':
 * @property string $mail_id
 * @property string $mail_to
 * @property string $mail_cc
 * @property string $mail_subject
 * @property string $template_id
 *
 * The followings are the available model relations:
 * @property Templates $template
 * @property MailStoreNew[] $mailStoreNews
 */
class ActionMail extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return ActionMail the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'action_mail';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mail_to, mail_cc, mail_subject, template_id', 'required'),
			array('mail_to, mail_cc', 'length', 'max'=>200),
			array('mail_subject', 'length', 'max'=>500),
			array('template_id', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('mail_id, mail_to, mail_cc, mail_subject, template_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'template' => array(self::BELONGS_TO, 'Templates', 'template_id'),
			'mailStoreNews' => array(self::HAS_MANY, 'MailStoreNew', 'mail_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'mail_id' => 'Mail',
			'mail_to' => 'Mail To',
			'mail_cc' => 'Mail Cc',
			'mail_subject' => 'Mail Subject',
			'template_id' => 'Template',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('mail_id',$this->mail_id,true);
		$criteria->compare('mail_to',$this->mail_to,true);
		$criteria->compare('mail_cc',$this->mail_cc,true);
		$criteria->compare('mail_subject',$this->mail_subject,true);
		$criteria->compare('template_id',$this->template_id,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}